package com.toune.movie.mvp.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.siberiadante.customdialoglib.CustomDialog;
import com.toune.movie.R;
import com.toune.movie.base.Api;
import com.toune.movie.base.AppConstant;
import com.toune.movie.base.BaseFragment;
import com.toune.movie.mvp.activity.VipVideoUrlActivity;
import com.toune.movie.mvp.adapter.VideoAdapter;
import com.toune.movie.mvp.contract.MovieVipContract;
import com.toune.movie.mvp.presenter.MovieVipPresenter;
import com.toune.movie.vo.VideoVo;
import com.vondear.rxui.view.RxRunTextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by Administrator on 2018/5/9.
 */

public class MovieVipFragment extends BaseFragment<MovieVipPresenter> implements MovieVipContract.View {
    @BindView(R.id.get_vip_url_btn)
    Button getVipUrlBtn;
    Unbinder unbinder;
    private static MovieVipFragment fragment;
    @BindView(R.id.tv_runtitle)
    RxRunTextView tvRuntitle;
    @BindView(R.id.rclview)
    RecyclerView rclview;
    Unbinder unbinder1;
    private VideoAdapter videoAdapter;

    public static MovieVipFragment newInstance() {
        if (fragment == null) {
            fragment = new MovieVipFragment();
        }
        return fragment;
    }

    @Override // 实例化presenter
    public MovieVipPresenter initPresenter() {
        return new MovieVipPresenter();
    }

    @Override
    public void loadMore() {

    }

    @Override
    public void refreData() {

    }

    @Override
    protected void initData() {

    }

    private List<VideoVo> videoVos = new ArrayList<>();

    @Override
    public void init(Bundle savedInstanceState) {
//        progressWv.loadUrl("http://www.5ifxw.com/vip/");
        for (int i = 0; i < AppConstant.VideoImages.length; i++) {
            VideoVo videoVo = new VideoVo();
            videoVo.setImage(AppConstant.VideoImages[i]);
            videoVo.setUrl(AppConstant.VideoUrls[i]);
            videoVos.add(videoVo);
        }
        notifyAdapter();
    }

    private void notifyAdapter() {
        if (videoAdapter == null) {
            videoAdapter = new VideoAdapter(R.layout.adapter_video, videoVos);
            rclview.setLayoutManager(new GridLayoutManager(getContext(), 2));
            rclview.setAdapter(videoAdapter);
            videoAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                    Intent intent = new Intent(getContext(), VipVideoUrlActivity.class);
                    intent.putExtra("url",videoVos.get(position).getUrl());
                    getContext().startActivity(intent);
                }
            });
        } else {
            videoAdapter.notifyDataSetChanged();
        }
    }

    @Override
    public int getLayoutResId() {
        return R.layout.fragment_movie_vip;
    }

    @Override
    public void showError(String msg) {

    }

    @Override
    public void useNightMode(boolean isNight) {

    }
}
